﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;

public class EventManager
{
    public static void addEventListener(GameObject obj, EventTriggerType type, UnityAction<BaseEventData> callback, bool bPlayAudio = false)
    {
        EventTrigger et = obj.GetComponent<EventTrigger>();
        if (et == null)
        {
            et = obj.AddComponent<EventTrigger>();
        }

        EventTrigger.TriggerEvent te = new EventTrigger.TriggerEvent();
        te.AddListener((BaseEventData eventData) => {
            if (bPlayAudio)
                AudioManager.PlaySound("btn");
            callback(eventData);
        });
        EventTrigger.Entry entry = new EventTrigger.Entry();
        entry.eventID = type;
        entry.callback = te;

        List<EventTrigger.Entry> entrys = et.triggers;
        entrys.Add(entry);
    }
}
